package com.jhgsys.internal.incentive.controller.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveRewardClause;
import com.jhgsys.internal.incentive.entity.IncentiveRewardClauseRule;
import com.jhgsys.internal.incentive.service.IIncentiveRewardClauseRuleService;
import com.jhgsys.internal.incentive.service.IIncentiveRewardClauseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Slf4j
@Validated
@Controller
public class CommonIncentiveRewardClauseController extends BaseController {


    @Autowired
    private IIncentiveRewardClauseService incentiveRewardClauseService;

    @Autowired
    private IIncentiveRewardClauseRuleService incentiveRewardClauseRuleService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "common/incentiveRewardClause")
    public String commonIncentiveRewardClause(){
        return FebsUtil.view("incentive/common/incentiveRewardClauseCommon");
    }

    /**
     * 查询（分页）
     * @author admin
     * @date 2024-08-08 13:20:26
     */
    @GetMapping("common/incentiveRewardClause/list")
    @ResponseBody
    public FebsResponse incentiveRewardClauseList(QueryRequest request, IncentiveRewardClause incentiveRewardClause) {
        if(StringUtils.isBlank(incentiveRewardClause.getTenantId())){
            incentiveRewardClause.setTenantId(getCurrentTenantId());
        }
        IPage<IncentiveRewardClause> incentiveRewardClauseIPage = incentiveRewardClauseService.findIncentiveRewardClausePage(request, incentiveRewardClause);
        Map<String, Object> dataTable = getDataTable(incentiveRewardClauseIPage);
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 查询（分页）
     * @author admin
     * @date 2024-08-08 13:20:26
     */
    @GetMapping("common/incentiveRewardClauseRule/list")
    @ResponseBody
    public FebsResponse peccancyClauseRuleList(IncentiveRewardClauseRule incentiveRewardClauseRule, QueryRequest request) {
        if(StringUtils.isBlank(incentiveRewardClauseRule.getTenantId())){
            incentiveRewardClauseRule.setTenantId(getCurrentTenantId());
        }
        IPage<IncentiveRewardClauseRule> incentiveRewardClauseRuleIPage = incentiveRewardClauseRuleService.findIncentiveRewardClauseRulePage(request, incentiveRewardClauseRule);
        Map<String, Object> dataTable = getDataTable(incentiveRewardClauseRuleIPage);
        return new FebsResponse().success().data(dataTable);
    }
}
